﻿using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Windows;
using Newtonsoft.Json;
using ZilLion.TPO2O.SDK;
using ZilLion.TPO2O.SDK.Request;

namespace RequestCreater
{
    /// <summary>
    ///     Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        public string HttpRequestGet(string url
        )
        {
            using (var http = new HttpClient())
            {
                http.Timeout = new TimeSpan(0, 0, 0, 30);
                var result = http.GetAsync(url).Result;
                var deresponsejson = result.Content.ReadAsStringAsync().Result;
                return deresponsejson;
            }
        }

        private void GetButton_OnClick(object sender, RoutedEventArgs e)
        {

            var defaultO2ORequester = new DefaultO2ORequester(TpType.KouBei);
            Tokenbox.Text = TokenContainer.Instance().TryGetToken();


            try
            {
                string body = this.Bodybox.Text;
                Dictionary<string, object> urlParamdic = null;
                if (UrlParambox.Text.IsNotNullOrEmpty())
                {
                   
                    try
                    {
                        urlParamdic=JsonConvert.DeserializeObject(UrlParambox.Text) as Dictionary<string, object>;

                    }
                    catch (Exception exception)
                    {
                      
                       
                    }
                    
                }
                var result = defaultO2ORequester.BusinessRequest("KouBeiTest", urlParamdic, body);
                Resultbox.Text = JsonConvert.SerializeObject(result);
            }
            catch (Exception exception)
            {
                Resultbox.Text = exception.ToString();
            }
        }
    }
}